$(document).ready(function(){
    var base_url = window.location.origin + '/';
//    base_url+="ippi/trunk/";
    //var base_url = "http://www.ippi.or.id/";
    //common properties
    var fa_ban        =   "<i class='fa fa-ban'></i>";
    var fa_info       =   "<i class='fa fa-info'></i>";
    var fa_warning    =   "<i class='fa fa-warning'></i>";
    var fa_success    =   "<i class='fa fa-check'></i>";
    
    //ADD NEW EVENT DATA
    $( "#frm_event" ).submit(function( event ) {
        //btn-close
        var btn_close       = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>�</button>";
        //common properties
        var judul           =   $("#judul").val();
        var place           =   $("#place").val();
        var content         =   $("#editor1").val();
        var userfile        =   $("#userfile").val();
        var gal_val         =   $('#gallery_val').val();
        var image_event     =   new Array();
        
        $('.image_event_cb').each(function() {
            var checked     =   $(this).is(':checked');
            if(checked){
                image_event.push($(this).val());
            }
        });
        
        //msg
        var msg             =   $("#msg");
        var fa_ban          =   "<i class=\"fa fa-ban\"></i>";
        var fa_info         =   "<i class=\"fa fa-info\"></i>";
        var fa_warning      =   "<i class=\"fa fa-warning\"></i>";
        var fa_success      =   "<i class=\"fa fa-check\"></i>";
        var msg_content     =   "<b>Alert!</b> ";
        
        //error count
        var error_count   =   0;
        if(judul === ""){
            msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#judul").focus();
            msg.fadeIn();
            error_count++;
            return false;
        }
        if(place === ""){
            msg_content   =   "<b>Alert!</b> Kolom Place Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#place").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(CKEDITOR.instances.editor1.getData() === ""){
            msg_content   =   "<b>Alert!</b> Isi Konten Event Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#editor1").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(image_event === ""){
            msg_content   =   "<b>Alert!</b> anda harus memilih satu gambar event dari gallery";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#from_gallery").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        
        if(error_count === 0) return true;
        else return false;
    });
    
    //UPDATE NEWS DATA
    $("#frm_news1").submit(function(e){
//        e.preventDefault();
        var judul       =   $("#judul").val();
        var tgl         =   $("#dtp_input1").val();
        var userfile    =   $("#userfile").val();
        //msg
        var msg           =   $("#msg");
        var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
        var fa_info       =   "<i class=\"fa fa-info\"></i>";
        var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
        var fa_success    =   "<i class=\"fa fa-check\"></i>";
        var msg_content   =   "<b>Alert!</b> ";
        if(judul === ""){
            msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";
            goToMessage();msg.hide();msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);msg.append(msg_content);
            $("#judul").focus();msg.fadeIn();
            return false;
        }
        if(tgl === ""){
            msg_content   =   "<b>Alert!</b> Tanggal Tidak Boleh Kosong";
            goToMessage();msg.hide();msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);msg.append(msg_content);
            $("#dtp_input1").focus();msg.fadeIn();
            return false;
        }
        if(CKEDITOR.instances.editor1.getData() === ""){
            msg_content   =   "<b>Alert!</b> Isi Berita Tidak Boleh Kosong";
            goToMessage();msg.hide();
            msg.empty();msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);msg.append(msg_content);
            $("#editor1").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(userfile === ""){
            msg_content   =   "<b>Alert!</b> Tanggal Tidak Boleh Kosong";
            goToMessage();msg.hide();msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);msg.append(msg_content);
            $("#userfile").focus();msg.fadeIn();
            return false;
        }
        return true;
    });
    
    //UPDATE EVENT DATA
    $( "#frm_update_event" ).submit(function( event ){
        //btn-close
        var btn_close = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>�</button>";
        //common properties
        var judul     =   $("#judul").val();
        var place     =   $("#place").val();
        var content   =   $("#editor1").val();
        //msg
        var msg           =   $("#msg");
        var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
        var fa_info       =   "<i class=\"fa fa-info\"></i>";
        var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
        var fa_success    =   "<i class=\"fa fa-check\"></i>";
        var msg_content   =   "<b>Alert!</b> ";
        
        //error count
        var error_count   =   0;
        if(judul === ""){
            msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#judul").focus();
            msg.fadeIn();
            error_count++;
            return false;
        }
        if(place === ""){
            msg_content   =   "<b>Alert!</b> Kolom Place Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#place").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(CKEDITOR.instances.editor1.getData() === ""){
            msg_content   =   "<b>Alert!</b> Isi Konten Event Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#editor1").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(error_count === 0) return true;
        else return false;
    });
    
    //cpass
    $( "#frm_cpass" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var opass           =   $("#opass").val();
        var npass           =   $("#npass").val();
        var cpass           =   $("#cpass").val();
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(opass === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Password Lama Harus diisi";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#opass").focus();
            msg.fadeIn();
            return false;
        }
        if(npass === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Password Baru Harus diisi";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#npass").focus();
            msg.fadeIn();
            return false;
        }
        if(npass !== ""){
            if(npass.length < 5){
                msg.hide();
                msg.empty();
                msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Password minimal 5 karakter";
                msg.append(msg_content);


                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");


                $("#npass").focus();
                msg.fadeIn();
                return false;
            }
        }
        if(cpass === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Konfirmasi Password Baru Harus diisi";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#cpass").focus();
            msg.fadeIn();
            return false;
        }
        if(cpass !== npass){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Konfirmasi Password Baru salah";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#cpass").focus();
            msg.fadeIn();
            return false;
        }
        

        var loading = $("div.loading");
        var myData = 'opass='+opass+"&npass="+npass+"&cpass="+cpass; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_ippi/cpass_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status == '1'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    $("#opass").val("");
                    $("#npass").val('');
                    $("#cpass").val('');
                    loading.hide();
                }
                else if(obj.status == '0'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                $("div#loading").hide(); //hide loading image
                $("div#bg-loading").hide();
                alert(thrownError);
            }
        });
        return false;
    });
    
    /*
     * E LIbrary - START------------------------------------------------------------------------
     */ 
    var options_elibrary = { 
        target: '#output',   // target element(s) to be updated with server response 
        beforeSubmit: elibrary_add_validation,  // pre-submit callback 
        success: afterSuccess,  // post-submit callback 
        complete:function(XMLHTTPRequest, textStatus) { 
            elibrary_success(XMLHTTPRequest, textStatus);
        },
        resetForm: true        // reset the form after successful submit 
    }; 

     $('#elibrary_form_new').submit(function() { 
            var content     =   $("#editor1");
            content.css('visibility','collapse');
            $(this).ajaxSubmit(options_elibrary);  			
            // always return false to prevent standard browser submit and page navigation 
            return false; 
    }); 
    function elibrary_add_validation(){
        $('.loading').show();
            //check whether browser fully supports all File API
        if (window.File && window.FileReader && window.FileList && window.Blob)
        {
            var judul       =   $("#judul");
            var kategori    =   $("#kategori");
            var content     =   $("#editor1");
            var userfile    =   $("#userfile"); //file e library
            var imageinput  =   $("#imageinput"); //cover file image
            
            //msg
            var msg           =   $("#msg");
            var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
            var fa_info       =   "<i class=\"fa fa-info\"></i>";
            var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
            var fa_success    =   "<i class=\"fa fa-check\"></i>";
            var msg_content   =   "<b>Alert!</b> ";
            
            var error_count   =   0;
            if(judul.val() === ""){
                msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";goToMessage();msg.hide();msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);msg.append(msg_content);judul.focus();
                msg.fadeIn();error_count++;$('.loading').hide();
                return false;
            }
            if(kategori.val() === ""){
                msg_content   =   "<b>Alert!</b> Pilih salah satu kategori";goToMessage();msg.hide();msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);msg.append(msg_content);kategori.focus();
                msg.fadeIn();error_count++;$('.loading').hide();
                return false;
            }
            if(CKEDITOR.instances.editor1.getData() === ''){
                msg_content   =   "<b>Alert!</b> Isi Konten Tidak Boleh Kosong";
                goToMessage();msg.hide();msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);msg.append(msg_content);
                $("#editor1").focus();$('.loading').hide();
                msg.fadeIn();error_count++;return false;
            }
            
            content.html(CKEDITOR.instances.editor1.getData());
            if( !userfile.val()) //check empty input filed
            {
                msg_content   =   "<b>Alert!</b> Pilih file untuk diupload";
                goToMessage();msg.hide();msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);msg.append(msg_content);
                userfile.focus();$('.loading').hide();
                msg.fadeIn();error_count++;return false;
            }
            if( !imageinput.val()) //check empty input filed
            {
                msg_content   =   "<b>Alert!</b> Masukkan gambar cover untuk diupload";
                goToMessage();msg.hide();msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);msg.append(msg_content);
                imageinput.focus();$('.loading').hide();
                msg.fadeIn();error_count++;return false;
            }
            
            /*
             * userfile : file properties
             */
            
            var filesize = userfile[0].files[0].size;
            var filetype = userfile[0].files[0].type;
//            console.log(filetype);
            
            
            /*
             * cover image : image properties
             */
            
            var imagesize = imageinput[0].files[0].size;
            var imagetype = imageinput[0].files[0].type;
//            console.log(imagetype);
//            
//            var fsize = $('#imageInput')[0].files[0].size; //get file size
//            var ftype = $('#imageInput')[0].files[0].type; // get file type
//
//
                            //allow only valid image file types 
            switch(imagetype)
            {
                case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg':
                    break;
                default:
                    msg_content   =   "<b>Alert!</b> Tipe file gambar salah";
                    goToMessage();msg.hide();msg.empty();
                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.append(fa_ban);msg.append(msg_content);
                    imageinput.focus();$('.loading').hide();
                    msg.fadeIn();error_count++;return false;
                    $('.loading').hide();
                    return false;
            }
//
//                //Allowed file size is less than 1 MB (1048576)
//            if(fsize>1048576) 
//            {
//                    alert("<b>"+bytesToSize(fsize) +"</b> Too big Image file! <br />Please reduce the size of your photo using an image editor.");
//                    return false
//            }
        }
        else
        {
                //Output error to older browsers that do not support HTML5 File API
                alert("Please upgrade your browser, because your current browser lacks some new features we need!");
                return false;
        }
    }
    
    function elibrary_success(XMLHTTPRequest, status){
        var obj = jQuery.parseJSON(XMLHTTPRequest.responseText);
        //msg
        var msg           =   $("#msg");
        var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
        var fa_info       =   "<i class=\"fa fa-info\"></i>";
        var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
        var fa_success    =   "<i class=\"fa fa-check\"></i>";
        var msg_content   =   "<b>Alert!</b> ";
        var loading = $("div.loading");
        if(obj.status === 1){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);
            msg_content   =   "<b>Success!</b> "+obj.msg;
            msg.append(msg_content);

            var city_wrapper = $("div#city_wrapper");
            city_wrapper.empty();
            city_wrapper.append(obj.list_city);
            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
            msg.fadeIn();loading.hide();
        }
        else if(obj.status === 0){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);
            msg_content   =   "<b>Alert!</b> "+obj.msg;
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();loading.hide();
        }
    }
    
       
    $( "#btn_elibrary_add" ).click(function( event ) {
        event.preventDefault();
          var btn_close = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>�</button>";
      //common properties
        var judul       =   $("#judul").val();
        var kategori    =   $("#kategori").val();
        var content     =   $("#editor1").val();
        var userfile    =   $("#userfile").val();
        var imageinput  =   $("#imageinput");
        //msg
        var msg           =   $("#msg");
        var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
        var fa_info       =   "<i class=\"fa fa-info\"></i>";
        var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
        var fa_success    =   "<i class=\"fa fa-check\"></i>";
        var msg_content   =   "<b>Alert!</b> ";

        //error count
        var error_count   =   0;
        if(judul === ""){
              msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";
              goToMessage();
              msg.hide();
              msg.empty();
              msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
              msg.append(fa_ban);
              msg.append(msg_content);
              $("#judul").focus();
              msg.fadeIn();
              error_count++;
              return false;
        }
        if(kategori === ""){
              msg_content   =   "<b>Alert!</b> Pilih salah satu kategori dokumen";
              goToMessage();
              msg.hide();
              msg.empty();
              msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
              msg.append(fa_ban);
              msg.append(msg_content);
              $("#kategori").focus();
              msg.fadeIn();
              error_count++;
              return false;
        }
        if(CKEDITOR.instances.editor1.getData() === ''){
              msg_content   =   "<b>Alert!</b> Isi Konten Tidak Boleh Kosong";
              goToMessage();
              msg.hide();
              msg.empty();
              msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
              msg.append(fa_ban);
              msg.append(msg_content);
              $("#editor1").focus();
              msg.fadeIn();
              error_count++;return false;
        }
        if(userfile === ""){
              msg_content   =   "<b>Alert!</b> anda harus memilih satu file untuk di-upload";
              goToMessage();
              msg.hide();
              msg.empty();
              msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
              msg.append(fa_ban);
              msg.append(msg_content);
              $("#userfile").focus();
              msg.fadeIn();
              error_count++;return false;
        }
        if(imageinput.val() === ""){
              msg_content   =   "<b>Alert!</b> anda harus memilih satu file gambar cover untuk di-upload";
              goToMessage();msg.hide();
              msg.empty();msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
              msg.append(fa_ban);
              msg.append(msg_content);
              $("#userfile").focus();
              msg.fadeIn();
              error_count++;return false;
        }
        
          $(this).hide();
          $("#elibrary_form").submit();
    });
    /*
     * E library - END-------------------------------------------------------------------------
     */
    
    
    
    //ELIBRARY EDIT
    $( "form#frm_update_elib" ).submit(function( event ) {
//        event.preventDefault();
          var btn_close = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>�</button>";
      //common properties
      var judul     =   $("#judul").val();
      var kategori  =   $("#kategori").val();
      var content   =   CKEDITOR.instances.editor1.getData();
      var userfile  =   $("#userfile").val();
      //msg
      var msg           =   $("#msg");
      var fa_ban        =   "<i class=\"fa fa-ban\"></i>";
      var fa_info       =   "<i class=\"fa fa-info\"></i>";
      var fa_warning    =   "<i class=\"fa fa-warning\"></i>";
      var fa_success    =   "<i class=\"fa fa-check\"></i>";
      var msg_content   =   "<b>Alert!</b> ";
      
      //error count
      var error_count   =   0;
      if(judul === ""){
            msg_content   =   "<b>Alert!</b> Judul Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#judul").focus();
            msg.fadeIn();
            error_count++;
            return false;
      }
      if(kategori === ""){
            msg_content   =   "<b>Alert!</b> Pilih salah satu kategori dokumen";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#kategori").focus();
            msg.fadeIn();
            error_count++;
            return false;
      }
      if(content === ''){
            msg_content   =   "<b>Alert!</b> Isi Konten Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#editor1").focus();
            msg.fadeIn();
            error_count++;return false;
      }
      if($("#new_file").is(":checked")){
          if(userfile === ""){
                msg_content   =   "<b>Alert!</b> anda harus memilih satu file untuk di-upload";
                goToMessage();
                msg.hide();
                msg.empty();
                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.append(fa_ban);
                msg.append(msg_content);
                $("#userfile").focus();
                msg.fadeIn();
                error_count++;return false;
          }
      }
    });
    //ELIBRARY CHECKBOX CLICKED
    
    $('#new_file').change(function() {
        if($(this).is(":checked")) {
            $("#file_baru").slideDown();
        }
        else{
            $("#file_baru").slideUp("faster");
        }      
    });
    //------    Fade Out Success Message (Update Event Data)  ---    
    setTimeout(fade_out_success, 6000);

    function fade_out_success() {
      $("#msg_success").fadeOut().empty();
    }
    //-----------------------------------------------------------  
    function preventDefault(e) {
        e.preventDefault();
    }
    $("a#process").click(function(e){
        preventDefault(e);
        //common properties
        var id  = $("a#process").data('id');
        var td_status = $("td#status");
        var td_action = $("td#action");

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id;
        BootstrapDialog.confirm('Are you sure process this Transaction?', function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_donation/process", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);


                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            td_status.empty();
                            td_status.append(label_success);
                            
                            td_action.empty();
                            td_action.append("&nbsp;-&nbsp;");
                            loading.hide();
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);


                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    
    //--------------- DONASI - S -------------------//
    //delete
    $("a.delete_donasi").click(function(e){
        preventDefault(e);
        var id_donasi       = $(this).data("id");
        var status_donasi   = $(this).data("status");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this data?";
        if(status_donasi === 1) confirm_msg = "Are you sure delete this data <b>PERMANENTLY</b> !?";
//        var base_url = "http://www.ippi.or.id/";

        
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_donasi;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_donation/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //undelete
    $("a.restore_donasi").click(function(e){
        preventDefault(e);
        var id_donasi       = $(this).data("id");
        var status_donasi   = $(this).data("status");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure RESTORE this data?";

        
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_donasi;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_donation/undelete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    //--------------- DONASI - E -------------------//
    
    // -------------- MEMBER - S -------------------//
    // add data function
    $( "#frm_member_add" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var email           =   $("#email").val();
        var name            =   $("#name").val();
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(email === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Email</i> field need to be filled";
            msg.append(msg_content);

            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            $("#email").focus();
            msg.fadeIn();
            return false;
        }
        if(email !== ""){
            if(validateEmail(email) === false){
                msg.hide();
                msg.empty();
                msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Please fill a valid email address";
                msg.append(msg_content);

                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");

                $("#email").focus();
                msg.fadeIn();return false;
            }
            
        }
        if(name === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> need to be filled";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(name.length < 5){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> is too short";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        
        var loading = $("div.loading");
        var myData = 'email='+email+"&name="+name; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_member/add_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status == '1'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    $("#email").val("");
                    $("#name").val('');
                    loading.hide();
                }
                else if(obj.status == '0'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        return false;
    });
    // update data function
    $( "#frm_member_update" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var idmember        =   $("#id").val();
        var status          =   $("#status").val();
        var name            =   $("#name").val();
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(name === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> need to be filled";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(name.length < 5){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> is too short";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(status === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> You must select status";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#status").focus();
            msg.fadeIn();
            return false;
        }
        //return false;
        var loading = $("div.loading");
        var myData = 'status='+status+"&name="+name+"&id="+idmember; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_member/detail_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status == '1'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    loading.hide();
                }
                else if(obj.status == '0'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        return false;
    });
    //hapus data member
    $("a.delete_member").click(function(e){
        preventDefault(e);
        var id_member       = $(this).data("id");
        var status_member   = $(this).data("status");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this member data?";
        if(status_member === 1) confirm_msg = "Are you sure delete this member data <b>PERMANENTLY</b> !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_member;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_member/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //restore data member
    $("a.restore_member").click(function(e){
        preventDefault(e);
        var id_member       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure restore this member data?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_member;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_member/undelete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //block member
    $("a.block_member").click(function(e){
        preventDefault(e);
        var id_member       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure <b>BLOCK</b> this member !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_member;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_member/block", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //unblock member
    $("a.unblock_member").click(function(e){
        preventDefault(e);
        var id_member       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure <b>UNBLOCK</b> this member !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_member;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_member/unblock", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    // -------------- MEMBER - E -------------------//
    
    
    // -------------- COORDINATOR - S -------------------//
    // add data function
    $("#frm_coordinator_add" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var email           =   $("#email").val();
        var name            =   $("#name").val();
        var province        =   $("#province").val();
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(email === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Email</i> field need to be filled";
            msg.append(msg_content);

            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            $("#email").focus();
            msg.fadeIn();
            return false;
        }
        if(email !== ""){
            if(validateEmail(email) === false){
                msg.hide();
                msg.empty();
                msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Please fill a valid email address";
                msg.append(msg_content);

                msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");

                $("#email").focus();
                msg.fadeIn();return false;
            }
            
        }
        if(name === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Admin <i>Name</i> need to be filled";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(name.length < 5){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Admin <i>Name</i> is too short";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(province === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Province Field need to be selected";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        
        var loading = $("div.loading");
        var myData = 'email='+email+"&name="+name+"&province="+province; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_coordinator/add_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status == '1'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    $("#email").val("");
                    $("#name").val('');
                    loading.hide();
                }
                else if(obj.status == '0'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        return false;
    });
    // update data function
    $("#frm_coordinator_update" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var idmember        =   $("#id").val();
        var province        =   $("#province").val();
        var status          =   $("#status").val();
        var name            =   $("#name").val();
        
        
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(name === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> need to be filled";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(name.length < 5){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Member <i>Name</i> is too short";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#name").focus();
            msg.fadeIn();
            return false;
        }
        if(province === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> You must select Province";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#province").focus();
            msg.fadeIn();
            return false;
        }
        if(status === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> You must select status";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            $("#status").focus();
            msg.fadeIn();
            return false;
        }
        //return false;
        var loading = $("div.loading");
        var myData = 'status='+status+"&name="+name+"&id="+idmember+"&province="+province; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_coordinator/detail_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status == '1'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    loading.hide();
                }
                else if(obj.status == '0'){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        return false;
    });
    //hapus data 
    $("a.delete_coordinator").click(function(e){
        preventDefault(e);
        var id       = $(this).data("id");
        var status_member   = $(this).data("status");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this member data?";
        if(status_member === 1) confirm_msg = "Are you sure delete this member data <b>PERMANENTLY</b> !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_coordinator/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //restore data 
    $("a.restore_coordinator").click(function(e){
        preventDefault(e);
        var id       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure restore this member data?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_coordinator/undelete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //block 
    $("a.block_coordinator").click(function(e){
        preventDefault(e);
        var id       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure <b>BLOCK</b> this Account !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_coordinator/block", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    //unblock 
    $("a.unblock_coordinator").click(function(e){
        preventDefault(e);
        var id_member       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure <b>UNBLOCK</b> this member !?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id_member;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_coordinator/unblock", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status == '1'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    // -------------- MEMBER - E -------------------//
    
    /*
     * author dinov
     * 20141017
     * form validation services add
     */
    $("#frm_services_add").submit(function(e){
        e.preventDefault();
        //common properties
        var name            =   $("#name");
        var telp            =   $("#phone");
        var address         =   $("#address");
        var province        =   $("#province");
        var city            =   $("#city");
        var desc            =   $("#desc");
        var lat             =   $("#lat");
        var long            =   $("#long");
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(name.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Service name </i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            name.focus();msg.fadeIn();return false;
        }
        if(telp.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Phone Number</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            telp.focus();msg.fadeIn();return false;
        }
        if(address.val() === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>address</i> field need to be filled";
            msg.append(msg_content);

            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            address.focus();msg.fadeIn();
            return false;
        }
        if(province.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>province</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            province.focus();msg.fadeIn();
            return false;
        }
        if(city.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>City</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            city.focus();msg.fadeIn();
            return false;
        }
        if(desc.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Description</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            desc.focus();msg.fadeIn();
            return false;
        }
        if(lat.val() === "" || long.val()===""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Latitude</i> field need to be filled, please click the map to get Location Latitude and Longitude";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();
            return false;
        }
        var loading = $("div.loading");
        var myData = 'name='+name.val()+"&phone="+telp.val()+"&address="+address.val()+"&desc="+desc.val()+"&city="+city.val()+"&lat="+lat.val()+"&long="+long.val(); //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_services/add_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    loading.hide();
                    $("#frm_services_add")[0].reset();
                    $("div#city_wrapper").empty();
                    $("div#city_wrapper").append("<select class='form-control' id='city' name='city' disabled=''><option value=''> - Pilih Kabupaten - </option></select>");
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
               alert(thrownError);
                loading.hide(); //hide loading image
            }
        });
        return false;
    });
    
    /*
     * author dinov
     * 20141020
     * form validation services update
     */
    $("#frm_services_update").submit(function(e){
        e.preventDefault();
        //common properties
        var id              =   $("#id_services");
        var name            =   $("#name");
        var telp            =   $("#phone");
        var address         =   $("#address");
        var province        =   $("#province");
        var city            =   $("#city");
        var desc            =   $("#desc");
        var lat             =   $("#lat");
        var long            =   $("#long");
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(id.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Missing <i>ID</i>, please refresh the page";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            name.focus();msg.fadeIn();return false;
        }
        if(name.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Service name </i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            name.focus();msg.fadeIn();return false;
        }
        if(telp.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Phone Number</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            telp.focus();msg.fadeIn();return false;
        }
        if(address.val() === ""){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>address</i> field need to be filled";
            msg.append(msg_content);

            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            address.focus();msg.fadeIn();
            return false;
        }
        if(province.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>province</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            province.focus();msg.fadeIn();
            return false;
        }
        if(city.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>City</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            city.focus();msg.fadeIn();
            return false;
        }
        if(desc.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Description</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            desc.focus();msg.fadeIn();
            return false;
        }
        if(lat.val() === "" || long.val()===""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Latitude</i> field need to be filled, please click the map to get Location Latitude and Longitude";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();
            return false;
        }
        var loading = $("div.loading");
        var myData = 'id_services='+id.val()+'&name='+name.val()+"&phone="+telp.val()+"&address="+address.val()+"&desc="+desc.val()+"&city="+city.val()+"&lat="+lat.val()+"&long="+long.val(); //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_services/detail_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    goToMessage();
                    loading.hide();
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();goToMessage();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
               alert(thrownError);
               loading.hide(); //hide loading image
            }
        });
        return false;
    });
    
    /*
     *author dinov
     *20141020
     *hapus data services by clicking a link 
     */
    $("a.delete_services").click(function(e){
        preventDefault(e);
        var id              = $(this).data("id");
        var title           = $(this).data("title");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this <b>"+title+"</b> services data?";

        //msg properties
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id="+id;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_services/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status === 1){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    /*
     * author dinov
     * 20141017
     * on change select in add services form
     */
    $("#province").change(function(){
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var province = $("#province").val();
        var loading = $("div.loading");
        var myData = 'state_id='+province; //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_services/get_city_list", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);
                    
                    var city_wrapper = $("div#city_wrapper");
                    city_wrapper.empty();
                    city_wrapper.append(obj.list_city);
                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
//                    msg.fadeIn();
                    loading.hide();
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
               alert(thrownError);
                loading.hide(); //hide loading image
            }
        });
    });
    
    /*
     * 141119
     * form editing contact (admin_contact)
     * 
     */
    $("#frm_contact").submit(function(e){
        e.preventDefault();
        //common properties
        var email           =   $("#email");
        var telp            =   $("#phone");
        var address         =   $("#address");
        var province        =   $("#province");
        var city            =   $("#city");
        var desc            =   $("#ok");
        var lat             =   $("#lat");
        var long            =   $("#long");
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(email.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Please fill <i>email</i> field";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            email.focus();msg.fadeIn();return false;
        }
        if(address.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>address</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            address.focus();msg.fadeIn();
            return false;
        }
        if(telp.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Phone Number</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            telp.focus();msg.fadeIn();return false;
        }
        if(province.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>province</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            province.focus();msg.fadeIn();
            return false;
        }
        if(city.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>City</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            city.focus();msg.fadeIn();
            return false;
        }
        if(desc.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Keterangan</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            desc.focus();msg.fadeIn();
            return false;
        }
        if(lat.val() === "" || long.val()===""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Latitude</i> field need to be filled, please click the map to get Location Latitude and Longitude";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();
            return false;
        }
        var loading = $("div.loading");
        var myData = 'email='+email.val()+"&phone="+telp.val()+"&address="+address.val()+"&province="+province.val()+"&city="+city.val()+"&lat="+lat.val()+"&long="+long.val()+"&desc="+desc.val(); //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_contact/detail_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    goToMessage();
                    loading.hide();
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();goToMessage();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
               alert(thrownError);
               loading.hide(); //hide loading image
            }
        });
        return false;
    });
    
    // -------------- GALLERY (140910 by IAD) - S -------------------//
    //ADD NEW image
    var options_image = { 
        target: '#output',   // target element(s) to be updated with server response 
        beforeSubmit: validate_add_image_form_gallery,  // pre-submit callback 
        success: afterSuccess,  // post-submit callback 
        resetForm: true        // reset the form after successful submit 
    }; 
    $('#frm_add_image_gallery').submit(function() { 
            $(this).ajaxSubmit(options_image);  			
            // always return false to prevent standard browser submit and page navigation 
            return false; 
    });
    $("#frm_gallery_update" ).submit(function( event ) {
        event.preventDefault();
        //common properties
        var id      = $("#id_gallery");
        var title   = $("#title");
        if(id.val() === ''){
            msg_content   =   "<b>Alert!</b> Missing ID";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#title").focus();
            msg.fadeIn();
            $('.loading').hide();                    
            return false;
        }
        if(title.val() === ''){
            msg_content   =   "<b>Alert!</b> title must be filled";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#title").focus();
            msg.fadeIn();
            $('.loading').hide();    
            title.focus();                   
            return false;
        }
        
        
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(title.val().length < 5){
            msg.hide();
            msg.empty();
            msg.append(fa_ban);
            msg_content   =   "<b>Alert!</b> Title is too short";
            msg.append(msg_content);
            
            
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            
            
            title.focus();
            msg.fadeIn();
            return false;
        }
        //return false;
        var loading = $("div.loading");
        var myData = 'id_gallery='+id.val()+"&title="+title.val(); //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_gallery/detail_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);

                    goToMessage();
                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    loading.hide();
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);

                    goToMessage();
                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        return false;
    });
    
    
    //ADD NEW Video gallery
    var options_video = { 
        target: '#output',   // target element(s) to be updated with server response 
        beforeSubmit: validate_add_video_form_gallery,  // pre-submit callback 
        success: afterSuccess,  // post-submit callback 
        resetForm: true        // reset the form after successful submit 
    }; 
    $('#frm_add_video_gallery').submit(function(e) { 
        preventDefault(e);
            $(this).ajaxSubmit(options_video);  			
            // always return false to prevent standard browser submit and page navigation 
            return false; 
    });
    
    
    //DELETE
    $("a.delete_gallery").click(function(e){
        preventDefault(e);
        
        var id_gallery      = $(this).data("id");
        var status_gallery  = $(this).data("status");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this GALLERY data?";
        if(status_gallery === 1) confirm_msg = "Are you sure delete this data <b>PERMANENTLY</b> !?";
        
        var label_success   = "<span class=\"text-green\">Processed</span>";
        var msg             = $("div#msg");
        var msg_content     = "<b>Alert!</b> ";
        var loading         = $("div.loading");
        var url             = $(this).attr('href');
        
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                $.ajax({
                    type:       "POST",     // HTTP method POST or GET
                    url:        url,        // Where to make Ajax calls
                    data:       { 'id_gallery' : id_gallery }, 
                    beforeSend: function (){
                        loading.show();
                    },
                    success: function(response){  
                        var obj = jQuery.parseJSON(response);
                        if(obj.status === 1){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);
        
                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status == '0'){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    }
                });
                return false;
            }else {
                return false;
            }
        });

    });
    // -------------- GALLERY (140910 by IAD) - E -------------------//
    $("#report_process").click(function(e){
        preventDefault(e);
        var id_kasus    = $("#report_process").data('id');
        var confirm_msg     = "Are you sure to PROCESS this case?";

        
        var msg             =   $("div#pesan");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id_kasus="+id_kasus;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_reporting/mark_as_read", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status === 1){
                            msg.hide();
                            msg.empty();
                            msg.append("<h4>Already Proceed!</h4><p>kasus sudah ditindak lanjuti.</p>");

                            msg.removeClass("callout-info callout-danger").addClass("callout-info");
                            
                            $('html, body').animate({
                                scrollTop: $('.content-header').offset().top
                            }, 1000);
                            loading.hide();
                            msg.fadeIn();
                            $("#report_process").hide();
                            
                        }
                        else if(obj.status === '0'){
                            msg.hide();
                            msg.empty();
                            msg_content   =   "<h4>Alert!</h4> <p>"+obj.msg+"</p>";
                            msg.append(msg_content);
                            
                            msg.removeClass("callout-info").addClass("callout-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    
    // -------------- KASUS REPORTING (140910 by IAD) - S -------------------//
    $("a.delete_kasus").click(function(e){
        preventDefault(e);
        var id_kasus       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this CASE REPORT data?";
//        var base_url = "http://www.ippi.or.id/";

        
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id_kasus="+id_kasus;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_reporting/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status === 1){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status === 0){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    if($('#new_file').is(":checked")) {
        $("#file_baru").slideDown();
    }
    // -------------- KASUS REPORTING (140910 by IAD) - E -------------------//
    
    
    
    // -------------- SLIDESHOW (140924 by IAD) - S -------------------//
    var options = { 
        target: '#output',   // target element(s) to be updated with server response 
        beforeSubmit: beforeSubmit,  // pre-submit callback 
        success: afterSuccess,  // post-submit callback 
        resetForm: true        // reset the form after successful submit 
    }; 

     $('#MyUploadForm').submit(function() { 
            $(this).ajaxSubmit(options);  			
            // always return false to prevent standard browser submit and page navigation 
            return false; 
    }); 
    
    
    //delete slide show
    $("a.delete_slide").click(function(e){
        preventDefault(e);
        var id       = $(this).data("id");
        var cur_url         = window.location;
        var confirm_msg     = "Are you sure delete this SLIDE data?";
//        var base_url = "http://www.ippi.or.id/";

        
        var label_success =   "<span class=\"text-green\">Processed</span>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        
        var loading = $("div.loading");
        var myData = "id_slide="+id;
        BootstrapDialog.confirm(confirm_msg, function(result){
            if(result) {
                loading.show();
                jQuery.ajax({
                    type: "POST", // HTTP method POST or GET
                    url: base_url+"admin_slide/delete", //Where to make Ajax calls
                    dataType:"text", // Data type, HTML, json etc.
                    data:myData, //Form variables
                    success:function(response){
                        var obj = jQuery.parseJSON(response);
                        if(obj.status === 1){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_success);
                            msg_content   =   "<b>Success!</b> "+obj.msg;
                            msg.append(msg_content);

                            msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                            msg.fadeIn();
                            
                            loading.hide();
                            setTimeout(function(){
                                window.location = cur_url;
                            }, 3000);   
                        }
                        else if(obj.status === 0){
                            msg.hide();
                            msg.empty();
                            msg.append(fa_ban);
                            msg_content   =   "<b>Alert!</b> "+obj.msg;
                            msg.append(msg_content);
                            
                            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                            msg.fadeIn();
                            loading.hide();
                        }
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        loading.hide();
                        alert(thrownError);
                    }
                });
            }else {
                return false;
            }
        });
    });
    // -------------- SLIDESHOW (140924 by IAD) - E -------------------//
    // -------------- ADMIN PRODUCT (141026 by IAD) - S -------------------//
        
   
     /*
      * form add product validation before submit
      * @author dinov 20141026
      */
     $( "#frm_product_add" ).submit(function( event ) {
         event.preventDefault()
        //btn-close
        var btn_close       = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>�</button>";
        //common properties
        var name            =   $("#name").val();
        var harga           =   $("#harga").val();
        var content         =   $("#editor1").val();
        var image_event     =   new Array();
        
        $('.image_event_cb').each(function() {
            var checked     =   $(this).is(':checked');
            if(checked){
                image_event.push($(this).val());
            }
        });
        //msg
        var msg             =   $("#msg");
        var fa_ban          =   "<i class=\"fa fa-ban\"></i>";
        var fa_info         =   "<i class=\"fa fa-info\"></i>";
        var fa_warning      =   "<i class=\"fa fa-warning\"></i>";
        var fa_success      =   "<i class=\"fa fa-check\"></i>";
        var msg_content     =   "<b>Alert!</b> ";
        
        //error count
        var error_count   =   0;
        if(name === ""){
            msg_content   =   "<b>Alert!</b> Nama Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#name").focus();
            msg.fadeIn();
            error_count++;
            return false;
        }
        if(harga === ""){
            msg_content   =   "<b>Alert!</b> Harga Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#harga").focus();
            msg.fadeIn();
            error_count++;
            return false;
        }
        
        if(CKEDITOR.instances.editor1.getData() === ""){
            msg_content   =   "<b>Alert!</b> Deskripsi Tidak Boleh Kosong";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#editor1").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        if(image_event == ""){
            msg_content   =   "<b>Alert!</b> anda harus memilih satu gambar event dari gallery";
            goToMessage();
            msg.hide();
            msg.empty();
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.append(fa_ban);
            msg.append(msg_content);
            $("#from_gallery").focus();
            msg.fadeIn();
            error_count++;return false;
        }
        var myData = 'name='+name.val();//build a post data structure
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_product/aa", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_success);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);

                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();

                    loading.hide();
                    setTimeout(function(){
                        window.location = cur_url;
                    }, 3000);   
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);

                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
                loading.hide();
                alert(thrownError);
            }
        });
        if(error_count === 0) return true;
        else return false;
    });
    
    /*
    * @author Dinov
    * only allows numeric data
    */
    $("#harga").keydown(function (e){
        // Allow: backspace, delete, tab, escape, enter and .
        window.allow_number_only(e);
    });
    $("#stok").keydown(function (e){
        // Allow: backspace, delete, tab, escape, enter and .
        window.allow_number_only(e);
    });
    //allow only number
    $(".number").keydown(function (e){
        // Allow: backspace, delete, tab, escape, enter and .
        window.allow_number_only(e);
    });
    // -------------- ADMIN PRODUCT (141026 by IAD) - E -------------------//
    // Event Image Select
    $('a.image_event').each(function(){
        $(this).click(function(){
            var el      = $(this).find('.image_event_cb');
            var check   = el.is(":checked");
        
            if(check) {
                $(this).find('.iCheck-helper').trigger('click');
            } else {
                $(this).find('.iCheck-helper').trigger('click');
            }
            return false;
        });
    });
    
    // Event Image Select All
    $('#image_event_cball').click(function(e) {
        e.preventDefault();
        var checked     = $('.cb_all').is(":checked");
        
        if(checked){
            $('.cb_all').iCheck('uncheck');
            $('.check > label > div > ins').each(function() {
                $('.image_event_cb').iCheck('uncheck');
            });
        }else{
            $('.cb_all').iCheck('check');
            $('.check > label > div > ins').each(function() {
                $('.image_event_cb').iCheck('check');
            });
        }
        return false;
    });
    
    $('.check_all > div > ins').click(function(e) {
        e.preventDefault();
        var checked     = $('.cb_all').is(":checked");
        
        if(checked){
            $('.check > label > div > ins').each(function() {
                $('.image_event_cb').iCheck('check');
            });
        }else{
            $('.check > label > div > ins').each(function() {
                $('.image_event_cb').iCheck('uncheck');
            });
        }
        return false;
    });
    
    $(".modal-wide").on("show.bs.modal", function() {
        var height = $(window).height() - 200;
        $(this).find(".modal-body").css("max-height", height);
    });
    
    $('.modal-wide').on('hidden.bs.modal', function () {
        $('#cancel-upload-img').trigger('click');
        $("table tbody.files").empty();
        _load_image_data();
    });
    
    
    
    /*
     * controller : admin_member_ippi/add
     * validation form
     * 141126 dinov
     * @returns {undefined}
     */
    $("#frm_member_ippi_add").submit(function(e){
        e.preventDefault();
        //common properties
        var email                   =   $("#email");
        var name                    =   $("#name");
        var alamat                  =   $("#alamat");
        var province                =   $("#province1");
        var city                    =   $("#city");
        var tanggal_lahir_member    =   $("#tanggal_lahir_member");
        var tempat_lahir            =   $("#tempat_lahir");
        var pekerjaan               =   $("#pekerjaan");
        var income                  =   $("#income");
        var pendidikan              =   $("#pendidikan");
        var telp_rumah              =   $("#pekerjaan");
        var telp_kantor             =   $("#telp_rumah");
        var hp                      =   $("#hp");
        var fax                     =   $("#fax");
        var status_menikah          =   $("#status_menikah");
        var status_vct              =   $("#status_vct");
        var tahun_vct               =   $("#tahun_vct");
        var status_arv              =   $("#status_arv");
        var namejenis_arv           =   $("#namejenis_arv");
        var jumlah_anak_laki        =   $("#jumlah_anak_laki");
        var jumlah_anak_pr          =   $("#jumlah_anak_pr");
        var tanggal_lahir_anak1     =   $("#tanggal_lahir_anak1");
        var tanggal_lahir_anak2     =   $("#tanggal_lahir_anak2");
        var tanggal_lahir_anak3     =   $("#tanggal_lahir_anak3");
        var tanggal_lahir_anak4     =   $("#tanggal_lahir_anak4");
        var nama_anak1              =   $("#nama_anak1");
        var nama_anak2              =   $("#nama_anak2");
        var nama_anak3              =   $("#nama_anak3");
        var nama_anak4              =   $("#nama_anak4");
        var pendidikan_anak         =   $("#pendidikan_anak");
        var status_vct_anak         =   $("#status_vct_anak");
        var status_arv_anak         =   $("#status_arv_anak");
        var jenis_arv_anak          =   $("#jenis_arv_anak");
        var motivasi                =   $("#motivasi");
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg             =   $("div#msg");
        var msg_content     =   "<b>Alert!</b> ";
        if(email.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> Email field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            email.focus();msg.fadeIn();return false;
        }
        if(name.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Member name </i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            name.focus();msg.fadeIn();return false;
        }
        if(alamat.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Alamat</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            alamat.focus();msg.fadeIn();return false;
        }
        if(province.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>province</i> field need to be filled";
            msg.append(msg_content);
            msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            province.focus();msg.fadeIn();
            return false;
        }
        if(city.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>City</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            city.focus();msg.fadeIn();
            return false;
        }
        if(tanggal_lahir_member.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Birth date</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            tanggal_lahir_member.focus();msg.fadeIn();
            return false;
        }
        if(tempat_lahir.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Birth Place</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();tempat_lahir.focus();
            return false;
        }
        if(pekerjaan.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Job</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();pekerjaan.focus();
            return false;
        }
        if(income.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Monthly income</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();income.focus();
            return false;
        }
        if(pendidikan.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Education</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();pendidikan.focus();
            return false;
        }
        if(hp.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Phone Number</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();hp.focus();
            return false;
        }
        if(status_menikah.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>marital status</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();status_menikah.focus();
            return false;
        }
        
        
        if(status_vct.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>VCT Status</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();status_vct.focus();
            return false;
        }
        if(status_vct.val() === "1"){
            if(tahun_vct.val() === ""){
                msg.hide();msg.empty();
                msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>VCT Year</i> field need to be filled";
                msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.fadeIn();goToMessage();status_vct.focus();
                return false;
            }
        }
        
        
        if(status_arv.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>ARV Status</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();status_arv.focus();
            return false;
        }
        if(status_arv.val() !== "" || status_arv.val() !== "0"){
            if(namejenis_arv.val() === ""){
                msg.hide();msg.empty();
                msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Jenis ARV</i> field need to be filled";
                msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                msg.fadeIn();goToMessage();namejenis_arv.focus();
                return false;
            }
        }
        if(jumlah_anak_laki.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Jumlah Anak Lelaki</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();jumlah_anak_laki.focus();
            return false;
        }
        if(jumlah_anak_pr.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Jumlah Anak Perempuan</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();jumlah_anak_pr.focus();
            return false;
        }
        if(motivasi.val() === ""){
            msg.hide();msg.empty();
            msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Motivasi</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();status_vct.focus();
            return false;
        }
        var loading = $("div.loading");
        var myData = 'email='+email.val()+'&name='+name.val()+"&alamat="+alamat.val()+"&province="+province.val()+"&city="+city.val();
        myData+="&tanggal_lahir_member="+tanggal_lahir_member.val()+"&tempat_lahir="+tempat_lahir.val()+"&pekerjaan="+pekerjaan.val(); //build a post data structure
        myData+="&income="+income.val()+"&pendidikan="+pendidikan.val()+"&telp_rumah="+telp_rumah.val(); //build a post data structure
        myData+="&telp_kantor="+telp_kantor.val()+"&hp="+hp.val()+"&fax="+fax.val(); //build a post data structure
        myData+="&status_menikah="+status_menikah.val()+"&status_vct="+status_vct.val()+"&tahun_vct="+tahun_vct.val(); //build a post data structure
        myData+="&status_arv="+status_arv.val()+"&namejenis_arv="+namejenis_arv.val()+"&jumlah_anak_laki="+jumlah_anak_laki.val(); //build a post data structure
        myData+="&jumlah_anak_pr="+jumlah_anak_pr.val()+"&tanggal_lahir_anak1="+tanggal_lahir_anak1.val()+"&tanggal_lahir_anak2="+tanggal_lahir_anak2.val(); //build a post data structure
        myData+="&tanggal_lahir_anak3="+tanggal_lahir_anak3.val()+"&tanggal_lahir_anak4="+tanggal_lahir_anak4.val()+"&nama_anak1="+nama_anak1.val(); //build a post data structure
        myData+="&nama_anak2="+nama_anak2.val()+"&nama_anak2="+nama_anak3.val()+"&nama_anak3="+nama_anak1.val(); //build a post data structure
        myData+="&nama_anak4="+nama_anak4.val()+"&pendidikan_anak="+pendidikan_anak.val()+"&status_vct_anak="+status_vct_anak.val(); //build a post data structure
        myData+="&status_arv_anak="+status_arv_anak.val()+"&jenis_arv_anak="+jenis_arv_anak.val()+"&motivasi="+motivasi.val(); //build a post data structure
        loading.show();
        jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: base_url+"admin_member_ippi/add_act", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(response){
                var obj = jQuery.parseJSON(response);
                if(obj.status === 1){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Success!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-danger").addClass("alert-success");
                    msg.fadeIn();
                    goToMessage();
                    loading.hide();
                }
                else if(obj.status === 0){
                    msg.hide();
                    msg.empty();
                    msg.append(fa_ban);
                    msg_content   =   "<b>Alert!</b> "+obj.msg;
                    msg.append(msg_content);


                    msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
                    msg.fadeIn();goToMessage();
                    loading.hide();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
               alert(thrownError);
               loading.hide(); //hide loading image
            }
        });
        return false;
    });
    
    /*
     * controller : admin_chart/filter
     * purpose : validate form
     * 141127 dinov
     * @returns {undefined}
     */
    $("#frm_filter_chart").submit(function(e){
        var groupby     =   $("#groupby");
        var province    =   $("#province");
        var status_hiv  =   $("#status_hiv");
        var hub_pelaku  =   $("#hub_pelaku");
        var jenis_k     =   $("#jenis_k");
        
        var fa_ban        =   "<i class='fa fa-ban'></i>";
        var fa_info       =   "<i class='fa fa-info'></i>";
        var fa_warning    =   "<i class='fa fa-warning'></i>";
        var fa_success    =   "<i class='fa fa-check'></i>";
        var msg           =   $("div#msg");
        var msg_content   =   "<b>Alert!</b> ";
        
        if(groupby.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Grouping</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();groupby.focus();
            return false;
        }
        if(province.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Province</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();province.focus();
            return false;
        }
        if(status_hiv.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>HIV Status</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();status_hiv.focus();
            return false;
        }
        if(hub_pelaku.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Hubungan Pelaku</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();hub_pelaku.focus();
            return false;
        }
        if(jenis_k.val() === ""){
            msg.hide();msg.empty();msg.append(fa_ban);msg_content   =   "<b>Alert!</b> <i>Jenis Kekerasan</i> field need to be filled";
            msg.append(msg_content);msg.removeClass("alert-warning alert-info alert-success").addClass("alert-danger");
            msg.fadeIn();goToMessage();jenis_k.focus();
            return false;
        }
        return true;
    });
});




//untuk SLIDESHOW
function afterSuccess(){
    $('.loading').hide(); //hide submit button
}
function beforeSubmit(){
     $('.loading').show();
            //check whether browser fully supports all File API
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
        if( !$('#imageInput').val()) //check empty input filed
        {
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose one file at least</div>');
            $('.loading').hide();                    
            return false
        }

        var fsize = $('#imageInput')[0].files[0].size; //get file size
        var ftype = $('#imageInput')[0].files[0].type; // get file type


                        //allow only valid image file types 
        switch(ftype)
        {
            case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg':
                break;
            default:
                $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> Unsupported file type! please choose image file only</div>');
                $('.loading').hide();
                return false
        }

            //Allowed file size is less than 1 MB (1048576)
        if(fsize>1048576) 
        {
                alert("<b>"+bytesToSize(fsize) +"</b> Too big Image file! <br />Please reduce the size of your photo using an image editor.");
                return false
        }

        $('#submit-btn').hide(); //hide submit button
        $('#loading-img').show(); //hide submit button
        $("#output").html("");  
    }
    else
    {
            //Output error to older browsers that do not support HTML5 File API
            alert("Please upgrade your browser, because your current browser lacks some new features we need!");
            return false;
    }
}

function bytesToSize(bytes) {
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes === 0) return '0 Bytes';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
 }

//untuk gallery
//validasi sebelum submit upload image gallery
function validate_add_image_form_gallery(){
    $('.loading').show();
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
        var title = $("#title");
        if(title.val() === ''){
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose fill title field</div>');
            $("#output").fadeIn();
            title.focus();
            $('.loading').hide();                    
            return false;
        }
        if( !$('#imageInput').val()) //check empty input filed
        {
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose one file at least</div>');
            $('.loading').hide();  
            $("#output").fadeIn();
            return false
        }
    }
    else{
        $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> Please upgrade your browser, because your current browser lacks some new features we need!</div>');
        //Output error to older browsers that do not support HTML5 File API
        return false;
    }
}
function validate_add_video_form_gallery(){
    $('.loading').show();
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
        var title = $("#title");
        var video_file = $("#videoInput");
        var thumbnail_file = $("#imageInput");
        if(title.val() === ''){
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose fill title field</div>');
            $("#output").fadeIn();
            title.focus();
            $('.loading').hide();                    
            return false;
        }
        if(title.val().length < 6){
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> Title is too short </div>');
            $("#output").fadeIn();
            title.focus();
            $('.loading').hide();                    
            return false;
        }
        if( !video_file.val()) //check empty input filed
        {
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose one file at least</div>');
            $('.loading').hide();  
            $("#output").fadeIn();
            video_file.focus();
            return false
        }
        if( !thumbnail_file.val()) //check empty input filed
        {
            $("#output").hide();
            $("#output").empty();
            $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> You must choose one file for thumbnail at least</div>');
            $('.loading').hide();  
            $("#output").fadeIn();
            thumbnail_file.focus();
            return false
        }
//        var fsize = $('#imageInput')[0].files[0].size; //get file size
        var ftype = thumbnail_file[0].files[0].type; // get file type
//
//
                        //allow only valid image file types 
        switch(ftype)
        {
            case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg':
                break;
            default:
                $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> Unsupported file type! please choose image file only</div>');
                $('.loading').hide();
                return false
        }
    }
    else{
        $("#output").html('<div class="alert alert-danger alert-dismissable"><i class="fa fa-ban"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button><b>Alert!</b> Please upgrade your browser, because your current browser lacks some new features we need!</div>');
        //Output error to older browsers that do not support HTML5 File API
        return false;
    }
}


function goToMessage(){
    $("body, html").animate({ 
        scrollTop: $(".breadcrumb").offset().top 
    }, 600);
}
function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

//KHUSUS FORM GALLERY
$("#type").on('change', function() {
//    alert( this.value ); // or $(this).val()
    var userfile = $("#userfile");
    if($(this).val() === 'i'){
//        alert("i");
        $(".help_desc").empty();
        $(".help_desc").append(".jpg .png .jpeg");
        userfile.attr({accept:"image/*"});
    }
    if($(this).val() === 'v'){
        userfile.attr({accept:"video/*"});
        $(".help_desc").empty();
        $(".help_desc").append(".mp4 .avi .wmv");
    }
  });
  //ADD GALLERY CHECKBOX CLICKED
    
    $('#new_file').change(function() {
        if($(this).is(":checked")) {
            $("#file_baru").slideDown();
        }
        else{
            $("#file_baru").slideUp("faster");
        }      
    });
    $("#append_file").click(function(){
        var file = '<input type="file" id="userfile" accept="image/*" name="userfile[]" />';
        $(".input-wrapper").append(file);
    });
    
    
    
    
    /*
     * author Dinov
     * 20141017
     * show google maps in services form and get lat long after click the map
     */
    function initialize() {
        var lat_field   = $("input#lat");
        var long_field  = $("input#long");
        var markers = [];
        var map = new google.maps.Map(document.getElementById('map-canvas'), {
          zoom: 3
        });

        var defaultBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(5.89, 95.319),
            new google.maps.LatLng(-1.33, 133.17));
        map.fitBounds(defaultBounds);

        // Create the search box and link it to the UI element.
        var input = /** @type {HTMLInputElement} */(
            document.getElementById('pac-input'));
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

        var searchBox = new google.maps.places.SearchBox(
          /** @type {HTMLInputElement} */(input));

        // [START region_getplaces]
        // Listen for the event fired when the user selects an item from the
        // pick list. Retrieve the matching places for that item.
        google.maps.event.addListener(searchBox, 'places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }
          for (var i = 0, marker; marker = markers[i]; i++) {
            marker.setMap(null);
          }

          // For each place, get the icon, place name, and location.
          markers = [];
          var bounds = new google.maps.LatLngBounds();
          for (var i = 0, place; place = places[i]; i++) {
            var image = {
              url: place.icon,
              size: new google.maps.Size(71, 71),
              origin: new google.maps.Point(0, 0),
              anchor: new google.maps.Point(17, 34),
              scaledSize: new google.maps.Size(25, 25)
            };

            // Create a marker for each place.
            var marker = new google.maps.Marker({
              map: map,
              icon: image,
              title: place.name,
              position: place.geometry.location
            });
            google.maps.event.addListener(marker, 'click', function(event) {
//              alert( "Latitude: "+event.latLng.lat()+" "+", longitude: "+event.latLng.lng() ); 
              lat_field.val(event.latLng.lat());
              long_field.val(event.latLng.lng());
            });
            markers.push(marker);

            bounds.extend(place.geometry.location);
          }

          map.fitBounds(bounds);
        });
        // [END region_getplaces]

        // Bias the SearchBox results towards places that are within the bounds of the
        // current map's viewport.
        google.maps.event.addListener(map, 'bounds_changed', function() {
          var bounds = map.getBounds();
          searchBox.setBounds(bounds);
        });
        google.maps.event.addListener(map, 'click', function(event) {
//              alert( "Latitude: "+event.latLng.lat()+" "+", longitude: "+event.latLng.lng() ); 
        lat_field.val(event.latLng.lat());
        long_field.val(event.latLng.lng());
      });

      }

      google.maps.event.addDomListener(window, 'load', initialize);




/*
* @author Dinov
* @param {type} evt
* @returns {Boolean}
* only allows numeric data
*/
function allow_number_only(e){
    // Allow: backspace, delete, tab, escape, enter and .
    if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
         // Allow: Ctrl+A
        (e.keyCode === 65 && e.ctrlKey === true) || 
         // Allow: home, end, left, right
        (e.keyCode >= 35 && e.keyCode <= 39)) {
             // let it happen, don't do anything
             return;
    }
    // Ensure that it is a number and stop the keypress
    if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
        e.preventDefault();
    }
}